
function AjaxCallToKeepSessionAlive() {
    jQuery.ajax({
        type: "POST",
        url: "WebService/GenericListsWebService.asmx/HelloWorld",
        data: "{}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (msg) {
        }
    });
}

jQuery(document).ready(function () {

    /* scroll on page anchors */
    jQuery('a.scroll').click(function () {
        jQuery('html, body').animate({
            scrollTop: jQuery(jQuery(this).attr('href')).offset().top
        }, 500);
        return false;
    });

    jQuery('a[title]').tooltip();
    jQuery('.datepicker input').on('changeDate', function () {
        jQuery(this).datepicker('hide');
    });

    jQuery('#bodyContent_lstBoxInclusion option').popover();
    jQuery('#bodyContent_lstBoxParameter option').popover({ placement: 'left' });


    jQuery('a.user-delete').click(function () {
        var res = confirm("Do you really want to delete this user?");
        if (!res) {
            return false;
        }
    });

    jQuery('a.outcome-delete').click(function () {
        var res = confirm("Do you really want to delete this outcome?");
        if (!res) {
            return false;
        }
    });

    jQuery('.alert').each(function () {
        var html = jQuery(this).html();
        html = '<button data-dismiss="alert" class="close">&#215;</button>' + html;
        jQuery(this).html(html);
    });


    /* false AJAX call to keep the session alive */
    setInterval('AjaxCallToKeepSessionAlive()', 1500);


    /**
    * Log In form validation script
    ********************************************************************************/

    jQuery('.login-form #bodyContent_txtLoginId').blur(function () {
        var parentObj = jQuery(this).parent().parent();
        if (jQuery.trim(jQuery(this).val()) == '') {
            jQuery(parentObj).addClass('error');
            jQuery(parentObj).find('.help-inline').text('Login Id is required');
        } else {
            jQuery(parentObj).removeClass('error');
            jQuery(parentObj).find('.help-inline').text('');
        }
    });

    jQuery('.login-form #bodyContent_txtPassword').blur(function () {
        var parentObj = jQuery(this).parent().parent();
        if (jQuery.trim(jQuery(this).val()) == '') {
            jQuery(parentObj).addClass('error');
            jQuery(parentObj).find('.help-inline').text('Password is required');
        } else {
            jQuery(parentObj).removeClass('error');
            jQuery(parentObj).find('.help-inline').text('');
        }
    });

    jQuery('.login-form #bodyContent_LoginButton').click(function () {

        var loginId = jQuery.trim(jQuery('.login-form #bodyContent_txtLoginId').val());
        var password = jQuery.trim(jQuery('.login-form #bodyContent_txtPassword').val());
        var error = 0;

        /* password */
        if (password == '') {
            var passwordParentObj = jQuery('.login-form #bodyContent_txtPassword').parent().parent();
            jQuery(passwordParentObj).addClass('error');
            jQuery(passwordParentObj).find('.help-inline').text('Password is required');
            jQuery('.login-form #bodyContent_txtPassword').focus();
            error = 1;
        }

        /* login id */
        if (loginId == '') {
            var loginParentObj = jQuery('.login-form #bodyContent_txtLoginId').parent().parent();
            jQuery(loginParentObj).addClass('error');
            jQuery(loginParentObj).find('.help-inline').text('Login Id is required');
            jQuery('.login-form #bodyContent_txtLoginId').focus();
            error = 1;
        }

        if (error == 1) {
            return false;
        }

    });


    /**
    * Forget Password form validation script
    ********************************************************************************/
    jQuery('#ForgetPassword #bodyContent_txtEmail').blur(function () {
        var error = 0;
        var parentObj = jQuery(this).parent().parent();

        if (jQuery.trim(jQuery(this).val()) == '') {
            jQuery(parentObj).addClass('error');
            jQuery(parentObj).find('.help-block').text('Please enter email address');
            error = 1;
        } else if (!isValidEmailAddress(jQuery(this).val())) {
            jQuery(parentObj).addClass('error');
            jQuery(parentObj).find('.help-block').text('Invalid email address entered');
            error = 1;
        }

        if (!error) {
            jQuery(parentObj).removeClass('error');
            jQuery(parentObj).find('.help-block').text('');
        }
    });

    jQuery('#ForgetPassword #bodyContent_ResetPasswordButton').click(function () {
        var error = 0;
        var parentObj = jQuery('#ForgetPassword #bodyContent_txtEmail').parent().parent();

        if (jQuery.trim(jQuery('#ForgetPassword #bodyContent_txtEmail').val()) == '') {
            jQuery(parentObj).addClass('error');
            jQuery(parentObj).find('.help-block').text('Please enter email address');
            error = 1;
        } else if (!isValidEmailAddress(jQuery('#ForgetPassword #bodyContent_txtEmail').val())) {
            jQuery(parentObj).addClass('error');
            jQuery(parentObj).find('.help-block').text('Invalid email address entered');
            error = 1;
        }

        if (error == 0) {
            jQuery(parentObj).removeClass('error');
            jQuery(parentObj).find('.help-block').text('');
        } else {
            jQuery('#ForgetPassword #bodyContent_txtEmail').focus();
            return false;
        }
    });


    /**
    * Registered User form validation script
    ********************************************************************************/

    jQuery('#UserRegistrationForm #bodyContent_txtLoginId').blur(function () {
        var parentObj = jQuery(this).parent().parent();
        if (jQuery.trim(jQuery(this).val()) == '') {
            jQuery(parentObj).addClass('error');
            jQuery(parentObj).find('.help-inline').text('Login Id is required');
        } else {
            jQuery(parentObj).removeClass('error');
            jQuery(parentObj).find('.help-inline').text('');
        }
    });

    jQuery('#UserRegistrationForm #bodyContent_txtPassword').blur(function () {
        var parentObj = jQuery(this).parent().parent();
        if (jQuery.trim(jQuery('#UserRegistrationForm bodyContent_IsEditMode').val()) == "0") {
            if (jQuery.trim(jQuery(this).val()) == '') {
                jQuery(parentObj).addClass('error');
                jQuery(parentObj).find('.help-inline').text('Password is required');
            } else {
                jQuery(parentObj).removeClass('error');
                jQuery(parentObj).find('.help-inline').text('');
            }
        }
    });

    jQuery('#UserRegistrationForm #bodyContent_txtConfirmPassword').blur(function () {
        var parentObj = jQuery(this).parent().parent();
        if (jQuery.trim(jQuery('#UserRegistrationForm bodyContent_IsEditMode').val()) == "0") {
            if (jQuery.trim(jQuery(this).val()) == '') {
                jQuery(parentObj).addClass('error');
                jQuery(parentObj).find('.help-inline').text('Confirm Password is required');
            } else {
                jQuery(parentObj).removeClass('error');
                jQuery(parentObj).find('.help-inline').text('');
            }
        }
    });

    jQuery('#UserRegistrationForm #bodyContent_txtFirstName').blur(function () {
        var parentObj = jQuery(this).parent().parent();
        if (jQuery.trim(jQuery(this).val()) == '') {
            jQuery(parentObj).addClass('error');
            jQuery(parentObj).find('.help-inline').text('First Name is required');
        } else {
            jQuery(parentObj).removeClass('error');
            jQuery(parentObj).find('.help-inline').text('');
        }
    });

    jQuery('#UserRegistrationForm #bodyContent_txtLastName').blur(function () {
        var parentObj = jQuery(this).parent().parent();
        if (jQuery.trim(jQuery(this).val()) == '') {
            jQuery(parentObj).addClass('error');
            jQuery(parentObj).find('.help-inline').text('Last Name is required');
        } else {
            jQuery(parentObj).removeClass('error');
            jQuery(parentObj).find('.help-inline').text('');
        }
    });

    jQuery('#UserRegistrationForm #bodyContent_txtEmail').blur(function () {
        var parentObj = jQuery(this).parent().parent();
        if (jQuery.trim(jQuery(this).val()) == '') {
            jQuery(parentObj).addClass('error');
            jQuery(parentObj).find('.help-inline').text('Email Address is required');
        } else if (!isValidEmailAddress(jQuery.trim(jQuery(this).val()))) {
            jQuery(parentObj).addClass('error');
            jQuery(parentObj).find('.help-inline').text('Invalid Email Address entered');
        } else {
            jQuery(parentObj).removeClass('error');
            jQuery(parentObj).find('.help-inline').text('');
        }
    });


    jQuery('#UserRegistrationForm #bodyContent_RegisterUserButton').click(function () {

        var error = 0;
        var loginId = jQuery.trim(jQuery('#UserRegistrationForm #bodyContent_txtLoginId').val());
        var password = jQuery.trim(jQuery('#UserRegistrationForm #bodyContent_txtPassword').val());
        var confirmPassword = jQuery.trim(jQuery('#UserRegistrationForm #bodyContent_txtConfirmPassword').val());
        var firstName = jQuery.trim(jQuery('#UserRegistrationForm #bodyContent_txtFirstName').val());
        var lastName = jQuery.trim(jQuery('#UserRegistrationForm #bodyContent_txtLastName').val());
        var emailAddress = jQuery.trim(jQuery('#UserRegistrationForm #bodyContent_txtEmail').val());

        if (loginId == '') {
            var loginParent = jQuery('#UserRegistrationForm #bodyContent_txtLoginId').parent().parent();
            jQuery(loginParent).addClass('error');
            jQuery(loginParent).find('.help-inline').text('Login Id is required');
            error = 1;
        }

        if (password == '') {
            var passwordParent = jQuery('#UserRegistrationForm #bodyContent_txtPassword').parent().parent();
            jQuery(passwordParent).addClass('error');
            jQuery(passwordParent).find('.help-inline').text('Password is required');
            error = 1;
        }

        if (confirmPassword == '') {
            var confirmPasswordParent = jQuery('#UserRegistrationForm #bodyContent_txtConfirmPassword').parent().parent();
            jQuery(confirmPasswordParent).addClass('error');
            jQuery(confirmPasswordParent).find('.help-inline').text('Confirm Password is required');
            error = 1;
        } else if (password != confirmPassword) {
            var confirmPasswordParent = jQuery('#UserRegistrationForm #bodyContent_txtConfirmPassword').parent().parent();
            jQuery(confirmPasswordParent).addClass('error');
            jQuery(confirmPasswordParent).find('.help-inline').text('Confirm Password does not match with Password');
            error = 1;
        }

        if (firstName == '') {
            var firstNameParent = jQuery('#UserRegistrationForm #bodyContent_txtFirstName').parent().parent();
            jQuery(firstNameParent).addClass('error');
            jQuery(firstNameParent).find('.help-inline').text('First Name is required');
            error = 1;
        }

        if (lastName == '') {
            var lastNameParent = jQuery('#UserRegistrationForm #bodyContent_txtLastName').parent().parent();
            jQuery(lastNameParent).addClass('error');
            jQuery(lastNameParent).find('.help-inline').text('Last Name is required');
            error = 1;
        }

        if (emailAddress == '') {
            var emailAddressParent = jQuery('#UserRegistrationForm #bodyContent_txtEmail').parent().parent();
            jQuery(emailAddressParent).addClass('error');
            jQuery(emailAddressParent).find('.help-inline').text('Email Address is required');
            error = 1;
        } else if (!isValidEmailAddress(emailAddress)) {
            var emailAddressParent = jQuery('#UserRegistrationForm #bodyContent_txtEmail').parent().parent();
            jQuery(emailAddressParent).addClass('error');
            jQuery(emailAddressParent).find('.help-inline').text('Invalid Email Address entered');
            error = 1;
        }

        if (error == 1) {
            return false;
        }

    });


    jQuery('#UserRegistrationForm #bodyContent_UpdateUserButton').click(function () {

        var error = 0;
        var loginId = jQuery.trim(jQuery('#UserRegistrationForm #bodyContent_txtLoginId').val());
        var password = jQuery.trim(jQuery('#UserRegistrationForm #bodyContent_txtPassword').val());
        var confirmPassword = jQuery.trim(jQuery('#UserRegistrationForm #bodyContent_txtConfirmPassword').val());
        var firstName = jQuery.trim(jQuery('#UserRegistrationForm #bodyContent_txtFirstName').val());
        var lastName = jQuery.trim(jQuery('#UserRegistrationForm #bodyContent_txtLastName').val());
        var emailAddress = jQuery.trim(jQuery('#UserRegistrationForm #bodyContent_txtEmail').val());

        if (password != confirmPassword) {
            var confirmPasswordParent = jQuery('#UserRegistrationForm #bodyContent_txtConfirmPassword').parent().parent();
            jQuery(confirmPasswordParent).addClass('error');
            jQuery(confirmPasswordParent).find('.help-inline').text('Confirm Password does not match with Password');
            error = 1;
        }

        if (firstName == '') {
            var firstNameParent = jQuery('#UserRegistrationForm #bodyContent_txtFirstName').parent().parent();
            jQuery(firstNameParent).addClass('error');
            jQuery(firstNameParent).find('.help-inline').text('First Name is required');
            error = 1;
        }

        if (lastName == '') {
            var lastNameParent = jQuery('#UserRegistrationForm #bodyContent_txtLastName').parent().parent();
            jQuery(lastNameParent).addClass('error');
            jQuery(lastNameParent).find('.help-inline').text('Last Name is required');
            error = 1;
        }

        if (emailAddress == '') {
            var emailAddressParent = jQuery('#UserRegistrationForm #bodyContent_txtEmail').parent().parent();
            jQuery(emailAddressParent).addClass('error');
            jQuery(emailAddressParent).find('.help-inline').text('Email Address is required');
            error = 1;
        } else if (!isValidEmailAddress(emailAddress)) {
            var emailAddressParent = jQuery('#UserRegistrationForm #bodyContent_txtEmail').parent().parent();
            jQuery(emailAddressParent).addClass('error');
            jQuery(emailAddressParent).find('.help-inline').text('Invalid Email Address entered');
            error = 1;
        }

        if (error == 1) {
            return false;
        }

    });


    /**
    * Reset Password form validation script
    ********************************************************************************/
    jQuery('#ResetPasswordForm #bodyContent_txtNewPassword').blur(function () {
        var error = 0;
        var parentObj = jQuery(this).parent().parent();

        if (jQuery.trim(jQuery(this).val()) == '') {
            jQuery(parentObj).addClass('error');
            jQuery(parentObj).find('.help-inline').text('Please enter New Password');
        } else {
            jQuery(parentObj).removeClass('error');
            jQuery(parentObj).find('.help-inline').text('');
        }
    });

    jQuery('#ResetPasswordForm #bodyContent_txtConfirmNewPassword').blur(function () {
        var error = 0;
        var parentObj = jQuery(this).parent().parent();

        if (jQuery.trim(jQuery(this).val()) == '') {
            jQuery(parentObj).addClass('error');
            jQuery(parentObj).find('.help-inline').text('Please enter Confirm New Password');
            error = 1;
        } else if (jQuery.trim(jQuery(this).val()) != jQuery.trim(jQuery('#ResetPasswordForm #bodyContent_txtNewPassword').val())) {
            jQuery(parentObj).addClass('error');
            jQuery(parentObj).find('.help-inline').text('New Password and Confirm New Password does not match');
            jQuery('#ResetPasswordForm #bodyContent_txtNewPassword').val('');
            jQuery(this).val('');
            jQuery('#ResetPasswordForm #bodyContent_txtNewPassword').focus();
            error = 1;
        }

        if (!error) {
            jQuery(parentObj).removeClass('error');
            jQuery(parentObj).find('.help-inline').text('');
        }
    });

    jQuery('#ResetPasswordForm #bodyContent_ResetPasswordButton').click(function () {
        var error = 0;

        if (jQuery.trim(jQuery('#ResetPasswordForm #bodyContent_txtNewPassword').val()) == '') {
            var parentObj = jQuery('#ResetPasswordForm #bodyContent_txtNewPassword').parent().parent();
            jQuery(parentObj).addClass('error');
            jQuery(parentObj).find('.help-inline').text('Please enter New Password');
            error = 1;
        }

        if (jQuery.trim(jQuery('#ResetPasswordForm #bodyContent_txtConfirmNewPassword').val()) == '') {
            var parentObj = jQuery('#ResetPasswordForm #bodyContent_txtConfirmNewPassword').parent().parent();
            jQuery(parentObj).addClass('error');
            jQuery(parentObj).find('.help-inline').text('Please enter Confirm New Password');
            error = 1;
        } else if (jQuery.trim(jQuery('#ResetPasswordForm #bodyContent_txtNewPassword').val()) != jQuery.trim(jQuery('#ResetPasswordForm #bodyContent_txtConfirmNewPassword').val())) {
            var parentObj = jQuery('#ResetPasswordForm #bodyContent_txtConfirmNewPassword').parent().parent();
            jQuery(parentObj).addClass('error');
            jQuery(parentObj).find('.help-inline').text('New Password and Confirm New Password does not match');
            jQuery('#ResetPasswordForm #bodyContent_txtNewPassword').val('');
            jQuery('#ResetPasswordForm #bodyContent_txtConfirmNewPassword').val('');
            jQuery('#ResetPasswordForm #bodyContent_txtNewPassword').focus();
            error = 1;
        }

        if (error == 1) {
            return false;
        }

    });


    /**
    * Change Password Form validation script
    ********************************************************************************/

    jQuery('#ChangePasswordForm #bodyContent_txtOldPassword').blur(function () {
        var parentObj = jQuery(this).parent().parent();
        if (jQuery.trim(jQuery(this).val()) == '') {
            jQuery(parentObj).addClass('error');
            jQuery(parentObj).find('.help-inline').text('Please enter your current password');
        } else {
            jQuery(parentObj).removeClass('error');
            jQuery(parentObj).find('.help-inline').text('');
        }
    });

    jQuery('#ChangePasswordForm #bodyContent_txtPassword').blur(function () {
        var parentObj = jQuery(this).parent().parent();
        if (jQuery.trim(jQuery(this).val()) == '') {
            jQuery(parentObj).addClass('error');
            jQuery(parentObj).find('.help-inline').text('Please enter new password');
        } else {
            jQuery(parentObj).removeClass('error');
            jQuery(parentObj).find('.help-inline').text('');
        }
    });

    jQuery('#ChangePasswordForm #bodyContent_txtConfirmPassword').blur(function () {
        var parentObj = jQuery(this).parent().parent();
        if (jQuery.trim(jQuery(this).val()) == '') {
            jQuery(parentObj).addClass('error');
            jQuery(parentObj).find('.help-inline').text('Please re-enter new password');
        } else {
            jQuery(parentObj).removeClass('error');
            jQuery(parentObj).find('.help-inline').text('');
        }
    });

    jQuery('#ChangePasswordForm #bodyContent_ChangePasswordButton').click(function () {

        var error = 0;
        var oldPassword = jQuery.trim(jQuery('#ChangePasswordForm #bodyContent_txtOldPassword').val());
        var newPassword = jQuery.trim(jQuery('#ChangePasswordForm #bodyContent_txtPassword').val());
        var confirmPassword = jQuery.trim(jQuery('#ChangePasswordForm #bodyContent_txtConfirmPassword').val());

        if (oldPassword == '') {
            var loginParent = jQuery('#ChangePasswordForm #bodyContent_txtOldPassword').parent().parent();
            jQuery(loginParent).addClass('error');
            jQuery(loginParent).find('.help-inline').text('Please enter your current password');
            error = 1;
        }

        if (newPassword == '') {
            var passwordParent = jQuery('#ChangePasswordForm #bodyContent_txtPassword').parent().parent();
            jQuery(passwordParent).addClass('error');
            jQuery(passwordParent).find('.help-inline').text('Please enter new password');
            error = 1;
        }

        if (confirmPassword == '') {
            var confirmPasswordParent = jQuery('#ChangePasswordForm #bodyContent_txtConfirmPassword').parent().parent();
            jQuery(confirmPasswordParent).addClass('error');
            jQuery(confirmPasswordParent).find('.help-inline').text('Please re-enter new password');
            error = 1;
        } else if (newPassword != confirmPassword) {
            var confirmPasswordParent = jQuery('#ChangePasswordForm #bodyContent_txtConfirmPassword').parent().parent();
            jQuery(confirmPasswordParent).addClass('error');
            jQuery(confirmPasswordParent).find('.help-inline').text('Confirm Password does not match with new password');
            error = 1;
        }

        if (error == 1) {
            return false;
        }

    });


    /**
    * Update Profile Form validation script
    ********************************************************************************/

    jQuery('#ProfileForm #bodyContent_txtFirstName').blur(function () {
        var parentObj = jQuery(this).parent().parent();
        if (jQuery.trim(jQuery(this).val()) == '') {
            jQuery(parentObj).addClass('error');
            jQuery(parentObj).find('.help-inline').text('First Name is required');
        } else {
            jQuery(parentObj).removeClass('error');
            jQuery(parentObj).find('.help-inline').text('');
        }
    });

    jQuery('#ProfileForm #bodyContent_txtLastName').blur(function () {
        var parentObj = jQuery(this).parent().parent();
        if (jQuery.trim(jQuery(this).val()) == '') {
            jQuery(parentObj).addClass('error');
            jQuery(parentObj).find('.help-inline').text('Last Name is required');
        } else {
            jQuery(parentObj).removeClass('error');
            jQuery(parentObj).find('.help-inline').text('');
        }
    });

    jQuery('#ProfileForm #bodyContent_txtEmail').blur(function () {
        var parentObj = jQuery(this).parent().parent();
        if (jQuery.trim(jQuery(this).val()) == '') {
            jQuery(parentObj).addClass('error');
            jQuery(parentObj).find('.help-inline').text('Email Address is required');
        } else if (!isValidEmailAddress(jQuery.trim(jQuery(this).val()))) {
            jQuery(parentObj).addClass('error');
            jQuery(parentObj).find('.help-inline').text('Invalid Email Address entered');
        } else {
            jQuery(parentObj).removeClass('error');
            jQuery(parentObj).find('.help-inline').text('');
        }
    });


    jQuery('#ProfileForm #bodyContent_UpdatePofileButton').click(function () {

        var error = 0;
        var firstName = jQuery.trim(jQuery('#ProfileForm #bodyContent_txtFirstName').val());
        var lastName = jQuery.trim(jQuery('#ProfileForm #bodyContent_txtLastName').val());
        var emailAddress = jQuery.trim(jQuery('#ProfileForm #bodyContent_txtEmail').val());

        if (firstName == '') {
            var firstNameParent = jQuery('#ProfileForm #bodyContent_txtFirstName').parent().parent();
            jQuery(firstNameParent).addClass('error');
            jQuery(firstNameParent).find('.help-inline').text('First Name is required');
            error = 1;
        }

        if (lastName == '') {
            var lastNameParent = jQuery('#ProfileForm #bodyContent_txtLastName').parent().parent();
            jQuery(lastNameParent).addClass('error');
            jQuery(lastNameParent).find('.help-inline').text('Last Name is required');
            error = 1;
        }

        if (emailAddress == '') {
            var emailAddressParent = jQuery('#ProfileForm #bodyContent_txtEmail').parent().parent();
            jQuery(emailAddressParent).addClass('error');
            jQuery(emailAddressParent).find('.help-inline').text('Email Address is required');
            error = 1;
        } else if (!isValidEmailAddress(emailAddress)) {
            var emailAddressParent = jQuery('#ProfileForm #bodyContent_txtEmail').parent().parent();
            jQuery(emailAddressParent).addClass('error');
            jQuery(emailAddressParent).find('.help-inline').text('Invalid Email Address entered');
            error = 1;
        }

        if (error == 1) {
            return false;
        }

    });

});


/**
* cross-browser html5 placeholder support script
********************************************************************************/
(function ($) {

    /**
    * Spoofs placeholders in browsers that don't support them (eg Firefox 3)
    *
    * Copyright 2011 Dan Bentley
    * Licensed under the Apache License 2.0
    *
    * Author: Dan Bentley [github.com/danbentley]
    */

    // Return if native support is available.
    if ("placeholder" in document.createElement("input")) return;

    $(document).ready(function () {
        $(':input[placeholder]').not(':password').each(function () {
            setupPlaceholder($(this));
        });

        $(':password[placeholder]').each(function () {
            setupPasswords($(this));
        });

        $('form').submit(function (e) {
            clearPlaceholdersBeforeSubmit($(this));
        });
    });

    function setupPlaceholder(input) {

        var placeholderText = input.attr('placeholder');

        setPlaceholderOrFlagChanged(input, placeholderText);
        input.focus(function (e) {
            if (input.data('changed') === true) return;
            if (input.val() === placeholderText) input.val('');
        }).blur(function (e) {
            if (input.val() === '') input.val(placeholderText);
        }).change(function (e) {
            input.data('changed', input.val() !== '');
        });
    }

    function setPlaceholderOrFlagChanged(input, text) {
        (input.val() === '') ? input.val(text) : input.data('changed', true);
    }

    function setupPasswords(input) {
        var passwordPlaceholder = createPasswordPlaceholder(input);
        input.after(passwordPlaceholder);

        (input.val() === '') ? input.hide() : passwordPlaceholder.hide();

        $(input).blur(function (e) {
            if (input.val() !== '') return;
            input.hide();
            passwordPlaceholder.show();
        });

        $(passwordPlaceholder).focus(function (e) {
            input.show().focus();
            passwordPlaceholder.hide();
        });
    }

    function createPasswordPlaceholder(input) {
        return $('<input>').attr({
            placeholder: input.attr('placeholder'),
            value: input.attr('placeholder'),
            id: input.attr('id'),
            readonly: true
        }).addClass(input.attr('class'));
    }

    function clearPlaceholdersBeforeSubmit(form) {
        form.find(':input[placeholder]').each(function () {
            if ($(this).data('changed') === true) return;
            if ($(this).val() === $(this).attr('placeholder')) $(this).val('');
        });
    }
})(jQuery);

function isValidEmailAddress(emailAddress) {
	var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
	return pattern.test(emailAddress);
}

/*
* Date Format 1.2.3
* (c) 2007-2009 Steven Levithan <stevenlevithan.com>
* MIT license
*
* Includes enhancements by Scott Trenda <scott.trenda.net>
* and Kris Kowal <cixar.com/~kris.kowal/>
*
* Accepts a date, a mask, or a date and a mask.
* Returns a formatted version of the given date.
* The date defaults to the current date/time.
* The mask defaults to dateFormat.masks.default.
*/

var dateFormat = function () {
    var token = /d{1,4}|m{1,4}|yy(?:yy)?|([HhMsTt])\1?|[LloSZ]|"[^"]*"|'[^']*'/g,
		timezone = /\b(?:[PMCEA][SDP]T|(?:Pacific|Mountain|Central|Eastern|Atlantic) (?:Standard|Daylight|Prevailing) Time|(?:GMT|UTC)(?:[-+]\d{4})?)\b/g,
		timezoneClip = /[^-+\dA-Z]/g,
		pad = function (val, len) {
		    val = String(val);
		    len = len || 2;
		    while (val.length < len) val = "0" + val;
		    return val;
		};

    // Regexes and supporting functions are cached through closure
    return function (date, mask, utc) {
        var dF = dateFormat;

        // You can't provide utc if you skip other args (use the "UTC:" mask prefix)
        if (arguments.length == 1 && Object.prototype.toString.call(date) == "[object String]" && !/\d/.test(date)) {
            mask = date;
            date = undefined;
        }

        // Passing date through Date applies Date.parse, if necessary
        date = date ? new Date(date) : new Date;
        if (isNaN(date)) throw SyntaxError("invalid date");

        mask = String(dF.masks[mask] || mask || dF.masks["default"]);

        // Allow setting the utc argument via the mask
        if (mask.slice(0, 4) == "UTC:") {
            mask = mask.slice(4);
            utc = true;
        }

        var _ = utc ? "getUTC" : "get",
			d = date[_ + "Date"](),
			D = date[_ + "Day"](),
			m = date[_ + "Month"](),
			y = date[_ + "FullYear"](),
			H = date[_ + "Hours"](),
			M = date[_ + "Minutes"](),
			s = date[_ + "Seconds"](),
			L = date[_ + "Milliseconds"](),
			o = utc ? 0 : date.getTimezoneOffset(),
			flags = {
			    d: d,
			    dd: pad(d),
			    ddd: dF.i18n.dayNames[D],
			    dddd: dF.i18n.dayNames[D + 7],
			    m: m + 1,
			    mm: pad(m + 1),
			    mmm: dF.i18n.monthNames[m],
			    mmmm: dF.i18n.monthNames[m + 12],
			    yy: String(y).slice(2),
			    yyyy: y,
			    h: H % 12 || 12,
			    hh: pad(H % 12 || 12),
			    H: H,
			    HH: pad(H),
			    M: M,
			    MM: pad(M),
			    s: s,
			    ss: pad(s),
			    l: pad(L, 3),
			    L: pad(L > 99 ? Math.round(L / 10) : L),
			    t: H < 12 ? "a" : "p",
			    tt: H < 12 ? "am" : "pm",
			    T: H < 12 ? "A" : "P",
			    TT: H < 12 ? "AM" : "PM",
			    Z: utc ? "UTC" : (String(date).match(timezone) || [""]).pop().replace(timezoneClip, ""),
			    o: (o > 0 ? "-" : "+") + pad(Math.floor(Math.abs(o) / 60) * 100 + Math.abs(o) % 60, 4),
			    S: ["th", "st", "nd", "rd"][d % 10 > 3 ? 0 : (d % 100 - d % 10 != 10) * d % 10]
			};

        return mask.replace(token, function ($0) {
            return $0 in flags ? flags[$0] : $0.slice(1, $0.length - 1);
        });
    };
} ();

// Some common format strings
dateFormat.masks = {
    "default": "ddd mmm dd yyyy HH:MM:ss",
    shortDate: "m/d/yy",
    mediumDate: "mmm d, yyyy",
    longDate: "mmmm d, yyyy",
    fullDate: "dddd, mmmm d, yyyy",
    shortTime: "h:MM TT",
    mediumTime: "h:MM:ss TT",
    longTime: "h:MM:ss TT Z",
    isoDate: "yyyy-mm-dd",
    isoTime: "HH:MM:ss",
    isoDateTime: "yyyy-mm-dd'T'HH:MM:ss",
    isoUtcDateTime: "UTC:yyyy-mm-dd'T'HH:MM:ss'Z'"
};

// Internationalization strings
dateFormat.i18n = {
    dayNames: [
		"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat",
		"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"
	],
    monthNames: [
		"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec",
		"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"
	]
};

// For convenience...
Date.prototype.format = function (mask, utc) {
    return dateFormat(this, mask, utc);
};